package Demo_8_28;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo05_1 {

   Demo05 demo05 = new Demo05();

   Scanner scanner = new Scanner(System.in);

   ArrayList<String> Name = new ArrayList<>();
   ArrayList<String> Id = new ArrayList<>();


   public void student(){

       while (true){

           System.out.println("1---添加姓名");
           System.out.println("2---删除");
           System.out.println("3---改");
           System.out.println("4---遍历");
           System.out.println("5---退出");

           int choose = scanner.nextInt();

           switch (choose){
               case 1:
                   zen();
                   break;
               case 2:
                   shan();
                   break;
               case 3:
                   gai();
                   break;
               case 4:
                   cha();
                   break;
               case 5:
                   System.exit(0);//退出
               default:
                   System.out.println("无效操作");
                   break;

           }

       }

   }

   public void zen(){


       System.out.println("姓名");
       String NAME = scanner.next();

       System.out.println("id");
       String ID = scanner.next();

       if (Name.contains(ID)){
           System.out.println("重复录入!");
       }else {
           demo05.setName(NAME);

           demo05.setId(ID);


           Name.add(demo05.getName());
           Id.add(demo05.getId());
       }

    }

    public void shan(){

        System.out.println("姓名");
        String name = scanner.next();
        if (Name.contains(name)){
            int delName = Name.indexOf(name);

            Name.remove(delName);
            Id.remove(delName);

            System.out.println("删除成功");
        }else {
            System.out.println("没有此人");
        }

    }

    public void gai(){
        System.out.println("输入原姓名");
        String passname = scanner.next();
        if (Name.contains(passname)){
            System.out.println("输入新姓名");
            String newname = scanner.next();
            System.out.println("输入新id");
            String newId = scanner.next();

            int nameid = Name.indexOf(passname);

            Name.set(nameid,newname);
            Id.set(nameid,newId);

            System.out.println("修改成功");
        }else {
            System.out.println("没有此人");
        }


    }

    public void cha(){

       for (int i =0;i<Name.size();i++){
           System.out.println("姓名-"+Name.get(i)+"\t"+"\t"+"ID-"+Id.get(i));
       }

    }
}
